unit UnitBusquedaPreinforme;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, DBGrids,
  sqldb, db, UnitMainForm, UnitNuevoInforme;

type

  { TFormBusquedaPreinforme }

  TFormBusquedaPreinforme = class(TForm)
    Datasource1: TDatasource;
    DBGrid1: TDBGrid;
    SQLQuery1: TSQLQuery;
    procedure DBGrid1CellClick(Column: TColumn);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormShow(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end; 

var
  FormBusquedaPreinforme: TFormBusquedaPreinforme;

implementation

{$R *.lfm}

{ TFormBusquedaPreinforme }

procedure TFormBusquedaPreinforme.FormShow(Sender: TObject);
var
  titulo : string;

begin
  titulo := InputBox('Busqueda de Preinformes', 'Ingrese parte del título', '');

  if titulo <> '' then
  begin
    if SQLQuery1.Active = true then
      SQLQuery1.Close;

    SQLQuery1.SQL.Text := 'select * from preinforme where prinf_titulo like ''%' + titulo
    + '%'' collate nocase order by prinf_titulo';

    SQLQuery1.Open;

    DBGrid1.Columns[0].Title.Caption := 'Código';
    DBGrid1.Columns[1].Title.Caption := 'Título';

    DBGrid1.Columns[0].Width := 70;
    DBGrid1.Columns[1].Width := 540;

    DBGrid1.Columns[2].Visible := false;
  end;
end;

procedure TFormBusquedaPreinforme.FormClose(Sender: TObject;
  var CloseAction: TCloseAction);
begin
  if SQLQuery1.Active = true then
    SQLQuery1.Close;
end;

procedure TFormBusquedaPreinforme.DBGrid1CellClick(Column: TColumn);
begin
  FormNuevoInforme.Edit4.Text := SQLQuery1.FieldByName('prinf_titulo').AsString;
  FormNuevoInforme.Memo1.Text := SQLQuery1.FieldByName('prinf_texto').AsString;

  Close();
end;

end.

